package com.yidu.drug.service.impl;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.yidu.drug.action.vo.InvoiceVo;
import com.yidu.drug.dao.InvoiceModelMapper;
import com.yidu.drug.model.InvoiceModel;
import com.yidu.drug.service.InvoiceService;

@Service
public class InvoiceServiceImpl implements InvoiceService{
	@Resource
	private InvoiceModelMapper InvoiceModelDao;
	
	/**
	 * 根据ID查询的方法
	 */
	@Override
	public InvoiceVo findById(String id) {
		InvoiceModel po=InvoiceModelDao.selectByPrimaryKey(id);
		InvoiceVo vo=new InvoiceVo();
		BeanUtils.copyProperties(po, vo);
		System.out.println("查询成功===============================");
		return vo;
	}

	/**
	 * 增加和修改的方法
	 */
	@Override
	public void saveOrUpdate(InvoiceVo vo) {
		System.out.println("进入增加或修改选择方法===============================");
		InvoiceModel po=new InvoiceModel();
		BeanUtils.copyProperties(vo, po);
		if(po.getInvoiceId()==null){
			System.out.println("进入增加的方法===============================");
			String foodId=UUID.randomUUID().toString();
			po.setInvoiceId(foodId);
			InvoiceModelDao.insertSelective(po);
		}else{
			System.out.println("进入修改的方法===============================");
			InvoiceModelDao.updateByPrimaryKeySelective(po);
		}
	}
	
	/**
	 * 增加方法
	 * @return 
	 */
	@Override
	public int add(InvoiceVo vo) {
		InvoiceModel po=new InvoiceModel();
		BeanUtils.copyProperties(vo, po);
		System.out.println("增加成功===============================");
		return InvoiceModelDao.insert(po);
	}
	/**
	 * 查询所有
	 */
	@Override
	public List<InvoiceModel> findAlls() {
		System.out.println("查询成功===============================");
		return InvoiceModelDao.findAlls();
	}

	/**
	 * 删除的方法
	 */
	@Override
	public void delete(String id) {
		InvoiceModelDao.deleteByPrimaryKey(id);
		System.out.println("删除成功===============================");
	}
}